round
Round this decimal to the nearest whole number.
Examples:
(-0.4).round()
returns0
(0.4).round()
returns0
(1.49999999999999999999).round()
returns1
(1.5).round()
returns2
Since
0.9.1
Round this decimal to a specific number of decimal places.
decimal.round(0)
is equivalent to decimal.round()
, i.e. rounding will be to the nearest whole number. Positive arguments round to an increasing number of decimal places, e.g. 1
rounds to the neartest tenth, 2
to the nearest hundredth, 3
to the nearest thousandth. Negative arguments round in the opposite way, i.e. -1
rounds to the nearest ten, -2
to the nearest hundred, -3
to the nearest thousand.
Examples:
(123.456).round(0)
returns123
(123.456).round(-1)
returns120
(123.456).round(1)
returns123.4
(123.456).round(-2)
returns100
(123.456).round(2)
returns123.45
(123.456).round(-3)
returns0
(123.456).round(3)
returns123.456
Since
0.9.1
Parameters
the number of decimal places to round